using System;
using System.Diagnostics;
using System.IO;
using System.Collections.Generic;
using org.tmatesoft.svn.core;
using org.tmatesoft.svn.core.wc;

namespace Subsync.Core.Subversion{
	public class SVNMove : CommandBase {
		public java.io.File Source;
		public java.io.File Destination;
		
		public void SVNmove(string Start, string End) {
			Source = new java.io.File(Start);
			Destination = new java.io.File(End);
		}
		
		public override void Execute ()
		{
			Console.WriteLine("SVN move Execution");
			
			Tools.setupLibrary();
			
			SVNClientManager cm = SVNClientManager.newInstance();
			SVNMoveClient mc = cm.getMoveClient();
			
			try {
				mc.doMove(this.Source, this.Destination);
			}
			catch (SVNException e) {
				throw new SVNExecuteException(e.getMessage());
			}
			
		}
		public override Dictionary<string, List<object>> getTokens ()
		{
			Dictionary<string, List<object>> ret = new Dictionary<string, List<object>> ();
			ret.Add("move",new List<object>() {"mv","move"});
			return ret;
		}
		
		public override List<KeyValuePair<string,initPointer>> getInitPointers() {
			List<KeyValuePair<string,initPointer>> ret = new List<KeyValuePair<string,initPointer>>();
			ret.Add(new KeyValuePair<string,initPointer>("move",new initPointer(this.handleCLI)));
			return ret;
		}
		
		public void handleCLI(Dictionary<string,List<object>> tokens) {
			if (tokens["move"].Count != 2) {
				Console.WriteLine("Not enough arguments: move requires at least 2 arguments");;
				return;
			}
			string SourceHelper = (string)tokens["move"][0];
			string DestinationHelper = (string)tokens["move"][1];
			this.SVNmove(SourceHelper, DestinationHelper);
			this.Execute();
		}
		
		public void SVNmove() {
			
		}

	}
}
